package Action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Dao.noticedao;
import Entity.Notice;
import Entity.User;
import mapper.Noticemapper;

/**
 * Servlet implementation class SendServlet
 */
@WebServlet("/SendServlet")
public class SendServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SendServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
        String user_id =request.getParameter("user_id");
        User user =null;
        HttpSession session = request.getSession();
        user=(User)session.getAttribute("user");
        String op_id =user.getUid();
        String title = request.getParameter("title");
        String context =request.getParameter("context");
        context.replace("\n", "<br>");
        Notice n =new Notice();
        n.setContent(context);
        n.setTitle(title);
        n.setFrom_Id(op_id);
        n.setTo_Id(user_id);
        Noticemapper nm = new noticedao();
        boolean a =nm.sendMessage(n);
        if(a){
        	request.setAttribute("me","淇℃伅鍙戦�佹垚鍔�");
        }
        else
        	request.setAttribute("me","淇℃伅鍙戦�佸け璐�");
        request.getRequestDispatcher("m_computer.jsp").forward(request,response);
	}

}
